package day07;

import java.util.Locale;
import java.util.Random;
import java.util.Scanner;

public class Guessing {
    public static void main(String[] args) {
//        int max = 1000,min = 1,num1 = 0;
//        int num = getRandem(max,min);
//        System.out.println(num);
//        while (true){
//            System.out.println(min+"-----"+max+"开始猜吧");
//            int guess = getScanner();
//            if (guess!=num){
//                if (guess>num){
//                    System.out.println("猜大了");
//                    if (max>guess){
//                        max = guess;
//                    }
//                }else {
//                    System.out.println("猜小了");
//                    if (min<guess){
//                        min = guess;
//                    }
//                }
//            }else {
//                System.out.println("猜对了");
//                break;
//            }
//        }

//

        while (true) {
            char[] vercode = getcharRandem(getRandem());
            String code = stringCharArray(vercode);
            System.out.println(code);
            System.out.println("请输入验证码进行验证");
            String verificationCode = getStringScanner();
            int a = getverificationjudge(code,verificationCode);
                if (a == 0) {
                    System.out.println("验证通过");
                    break;
                } else {
                    System.out.println("验证失败请重新输入");
                }

        }

    }
//    生成max---min随机数
    public static int getRandem(int max,int min){
        Random random = new Random();
        int a;
        if (min!=0){
         a = random.nextInt(max)+min;
        }else {
         a = random.nextInt(max+1);
        }
        return a;
    }
//    生成5----10随机数
    private static int getRandem(){
        Random random = new Random();
        int a = random.nextInt(6)+5;
        return a;
    }
//    生成char数组
    private static char[] getcharRandem(int arraylong){
        Random random = new Random();
        char[] h = stringArray(arraylong);
        for (int i = 0; i < h.length; i++) {
            h[i] = randemChar();
        }
        return h;
    }
    //生成随机码
    private static char randemChar() {
        Random random = new Random();
        char a = 0;
        int e = random.nextInt(3);
        switch (e) {
            case 0:
                char b = (char) (random.nextInt(26) + 65);
                a = b;
                break;
            case 1:
                char c = (char) (random.nextInt(26) + 97);
                a = c;
                break;
            case 2:
                char d = (char) (random.nextInt(10) + 48);
                a = d;
                break;
        }
        return a;
    }
    //cha数组转为字符串
    public static String stringCharArray(char[] array){
        String a = "";
        for (int i = 0; i < array.length; i++) {
            a += array[i];
        }
        return a;
    }
    //创建随机数组
    public static char[] stringArray(int num){
        char[] array = new char[num];
        return array;
    }
//    输入
    public static int getScanner(){
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        return a;
    }
    //输入字符串
    public static String getStringScanner(){
        Scanner scanner = new Scanner(System.in);
        String a = scanner.nextLine();
        return a;
    }
    //字符串小写相等判断
    public static int getverificationjudge(String code,String verificationCode){
        code = code.toLowerCase();
        verificationCode = verificationCode.toLowerCase();
        if (code.equals(verificationCode)){
            return 0;
        }else {
            return -1;
        }
    }
    //字符串长度判断
    public static int getStringLength(String code,String verificationCode){
        if (code.length()==verificationCode.length()){
            return 0;
        }else {
            return -1;
        }

    }
}
